package com.ahy231.mapper;

import com.ahy231.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ahy231
 * @date 2021/7/23 14:15
 * @description
 */
@Mapper
public interface LoginMapper extends BaseMapper<User> {

    @Select("SELECT r.role FROM `user` u LEFT JOIN user_role ur ON u.user_id = ur.user_id LEFT JOIN role r ON ur.role_id = r.role_id WHERE u.user_id = #{userId}")
    List<String> getRolesByUserId(long userId);

    @Select("SELECT role_id FROM role WHERE role = #{role}")
    Integer getRoleIdByRole(String role);
}
